import 'package:flutter/material.dart';
import 'package:flutter_deer/account/models/user_score_takeout_entity.dart';
import 'package:flutter_deer/widgets/state_layout.dart';

class TakeoutListProvider extends ChangeNotifier {

  UserScoreTakeoutPageEntity? _takeoutPage;
  List<UserScoreTakeoutEntity>? _list = [];
  StateType? _stateType = StateType.loading;
  int? _currentPage = 1;

  UserScoreTakeoutPageEntity? get takeoutPage => _takeoutPage;
  int? get total => _takeoutPage!.total;
  int? get current => _takeoutPage!.current;
  List<UserScoreTakeoutEntity>? get records => _takeoutPage!.records;
  List<UserScoreTakeoutEntity>? get list => _list;
  bool? get hasMore => _takeoutPage!.current!<_takeoutPage!.pages!;
  StateType? get stateType => _stateType;
  int? get currentPage => _currentPage;

  void setTakeoutPage(UserScoreTakeoutPageEntity? pageEntity){
    this._takeoutPage = pageEntity;
    this._currentPage = pageEntity!.current;
    if(pageEntity.current==1) {
      this._list = pageEntity!.records;
    }else{
      for(int i =0; i < pageEntity.records!.length; i++){
        UserScoreTakeoutEntity item = pageEntity.records!.elementAt(i);
        this._list!.add(item);
      }
    }
    this._stateType = StateType.takeOut;
    notifyListeners();
  }

}